const gulp = require("gulp");
const babel = require("gulp-babel");
const uglify = require("gulp-uglify");
const imagemin = require("gulp-imagemin");
const minifycss = require("gulp-minify-css");
//定义一个任务
//转义压缩js
gulp.task("js", function (cb) {
  //安装gulp插件，来完成任务
  console.log("编译,压缩");
  gulp
    .src("./src/js/*.js")
    .pipe(
      babel({
        presets: ["@babel/env"],
      })
    )
    .pipe(uglify())
    .pipe(gulp.dest("./dist/js"));
  cb();
});
// 直接压缩css
gulp.task("cssmin", function (cb) {
  gulp.src("./src/css/*css").pipe(minifycss()).pipe(gulp.dest("./dist/css"));
  cb();
});
// 压缩图片
gulp.task("imagemin", function (cb) {
  gulp.src("src/images/*").pipe(imagemin()).pipe(gulp.dest("dist/images"));
  cb();
});
//打包任务
gulp.task("build", gulp.series(["js", "cssmin", "imagemin"]), function () {
  console.log("项目的构件压缩完毕！");
});
